<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script th:src="@{/js/jquery.min.js}"></script>
    <link rel="stylesheet" th:href="@{/bootstrap/css/bootstrap.min.css}">
    <link href="//cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
    <script th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
    <script th:src="@{/js/jquery.validate.min.js}"></script>
    <script th:src="@{/js/messages_zh.min.js}"></script>
    <script th:src="@{/layer/layer.js}"></script>
    <script th:src="@{/js/md5.min.js}"></script>
    <script th:src="@{/js/common.js}"></script>
    <style type="text/css">
        body{
            background: #eee;
        }
        .wrapper{
            margin:80px
        }
        .form-signin{
            max-width: 420px;
            margin: 0 auto;
            background-color: #fff;
            padding: 10px 40px 50px;
            border: 1px solid #e5e5e5;
            border-radius: 10px;
        }
    </style>
</head>
<body>
<div class="wrapper">
    <form class="form-signin" name="loginForm" id="loginForm" method="post" style="width: 50%;margin: 0 auto">
        <h2 style="text-align: center;margin-bottom: 20px">用户登录</h2>
        <div class="form-group">
            <div class="row">
                <label class="form-label col-md-3" for="mobile">用户名</label>
                <div class="col-md-9">
                    <input name="mobile" id="mobile" class="form-control" type="text" placeholder="username"
                           required="true" minlength="11" maxlength="11">
                </div>
                <div class="col-md1"></div>
            </div>
        </div>
        <div class="form-group">
            <div class="row">
                <label class="form-label col-md-3" for="password">密码</label>
                <div class="col-md-9">
                    <input name="password" id="password" class="form-control" type="password" placeholder="password"
                           required="true" minlength="6" maxlength="16">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-4">
                <button class="btn btn-primary btn-block" type="reset" onclick="reset()">重置</button>
            </div>
            <div class="col-md-4">
                <a href="/register/toRegister"><button class="btn btn-primary btn-block">注册 </button></a>
            </div>
            <div class="col-md-4">
                <button class="btn btn-primary btn-block" type="submit" onclick="login()">登录</button>
            </div>
        </div>
    </form>
</div>


</body>
<script>
    function login() {
        $("#loginForm").validate({
            submitHandler: function (form) {
                doLogin();
            }
        })
    }

    function doLogin() {
        g_showLoading()
        var inputPass = $("#password").val();
        var salt = g_password_salt;
        var str = "" + salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);
        var password = md5(str);
        $.ajax({
            url: "/login/doLogin",
            type: "POST",
            data: {
                mobile: $("#mobile").val(),
                password: password
            },
            success: function (data) {
                layer.closeAll();
                if (data.code == 200) {
                    layer.msg("成功")
                    // 页面跳转
                    window.location.href = "/goods/toList"
                } else {
                    layer.msg(data.message)
                }
            },
            error: function () {
                layer.closeAll()
            }
        })
    }
</script>
</html>